// miniprogram/pages/consumption/day/day.js
const db = wx.cloud.database()
const _ = db.command
Page({
  data: {
    list: null
  },
  onLoad: function (options) {
    wx.showLoading({
      title: '正在加载...'
    })
  },
  onShow: function () {
    this.initData()
  },
  initData: function () {
    wx.cloud.callFunction({
      name: 'consume',
      data: {
        action: 'consume_day'
      },
      success: res => {
        wx.hideLoading()
        this.setData({
          list: res.result
        })
      },
      fail: err => {
        wx.hideLoading()
      }
    })
  },
  go: function (e) {
    let url = e.currentTarget.dataset.url
    wx.navigateTo({
      url: url
    })
  },
  initData1: function() {
    wx.showLoading({
      title: '正在加载...'
    })
    const start = new Date(new Date(new Date().toLocaleDateString()).getTime());
    const end = new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1);
    db.collection('consume').where({
      create_time: _.gte(start).and(_.lte(end))
    }).get({
      success: (res) => {
        wx.hideLoading()
        res.data.map(item => {
          item.create_time = item.create_time.getHours() + ':' + item.create_time.getMinutes()
        })
        this.setData({
          list: res.data,
          isLoading: true
        })
      }
    })
  }
})